//--------------------------------------------------
// ImPlot3D Example
// main.cpp
// Date: 2024-11-17
// Author: Breno Cunha Queiroz (brenocq.com)
//--------------------------------------------------
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include "implot.h"
#include "implot3d.h"
#include <GLFW/glfw3.h>
#include <iostream>
#include "imgui_internal.h"
// Callback to handle GLFW errors
void glfw_error_callback(int error, const char* description) { std::cerr << "GLFW Error " << error << ": " << description << std::endl; }
#include "imgui.h"

// bool MacStyleSliderFloat(const char* label, float* v, float v_min, float v_max) {
//     ImGuiContext* g = ImGui::GetCurrentContext();
//     const ImGuiStyle& style = g->Style;

//     // 布局设置
//     ImGui::PushID(label);
//     ImGui::BeginGroup();

//     // 显示标签
//     const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
//     ImGui::AlignTextToFramePadding();
//     ImGui::TextUnformatted(label);
//     ImGui::SameLine();

//     // 控件参数定义
//     const float slider_height = 16.0f;          // 轨道高度
//     const float grab_radius = 8.0f;             // 圆形滑块半径
//     const float total_width = 200.0f;           // 默认宽度
//     const float track_rounding = 4.0f;          // 轨道圆角
//     const float track_border_thickness = 1.5f;  // 边框粗细

//     // 获取当前可用宽度
//     const float avail_width = ImGui::GetContentRegionAvail().x;
//     const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

//     // 计算绘制位置
//     const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
//     const float track_y_center = cursor_pos.y + slider_height * 0.5f;
//     const float track_x1 = cursor_pos.x;
//     const float track_y1 = track_y_center - slider_height * 0.5f;
//     const float track_x2 = track_x1 + draw_width;
//     const float track_y2 = track_y_center + slider_height * 0.5f;

//     ImDrawList* draw_list = ImGui::GetWindowDrawList();

//     // 绘制轨道外边框（可选）
//     const ImVec4 track_border_color = ImVec4(0.3f, 0.3f, 0.3f, 1.0f);
//     const ImVec4 track_fill_color = ImVec4(0.15f, 0.15f, 0.15f, 1.0f);

//     // 绘制带圆角的轨道
//     draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
//                              ImGui::ColorConvertFloat4ToU32(track_fill_color), track_rounding);
//     draw_list->AddRect(cursor_pos, ImVec2(track_x2, track_y2),
//                        ImGui::ColorConvertFloat4ToU32(track_border_color), track_rounding,
//                        ImDrawFlags_None, track_border_thickness);

//     // 值映射到轨道上
//     const float t = (*v - v_min) / (v_max - v_min);
//     float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
//     const float grab_center_y = track_y_center;

//     // 绘制圆形滑块
//     const ImVec4 grab_color =
//         ImGui::IsItemActive() || ImGui::IsItemHovered()
//             ? ImVec4(0.0f, 0.6f, 1.0f, 1.0f)
//             : ImVec4(0.0f, 0.8f, 1.0f, 1.0f);
//     draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
//                                ImGui::ColorConvertFloat4ToU32(grab_color));

//     // 设置交互区域：轨道+滑块宽度范围内的矩形
//     const ImRect interact_rect(track_x1, track_y1 - grab_radius,
//                                track_x2, track_y2 + grab_radius);
//     bool value_changed = false;

//     if (ImGui::ItemSize(ImVec2(draw_width, slider_height))) {
//         if (ImGui::ItemAdd(interact_rect, g->CurrentWindow->GetID("slider"))) {
//             if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
//                 ImGui::ClearActiveID();
//             }

//             if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && interact_rect.Contains(g->IO.MousePos)) {
//                 ImGui::SetActiveID(g->CurrentWindow->GetID("slider"), g->CurrentWindow);
//                 float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
//                                          (track_x2 - track_x1 - 2 * grab_radius));
//                 *v = v_min + (v_max - v_min) * new_t;
//                 value_changed = true;
//             }
//             else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && ImGui::IsActiveID(g->CurrentWindow->GetID("slider"))) {
//                 float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
//                                          (track_x2 - track_x1 - 2 * grab_radius));
//                 *v = v_min + (v_max - v_min) * new_t;
//                 value_changed = true;
//             }
//         }
//     }

//     ImGui::EndGroup();
//     ImGui::PopID();

//     return value_changed;
// }




#include "imgui.h"

bool MacStyleSliderFloat(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    const float slider_height = 16.0f;
    const float grab_radius = 8.0f;
    const float total_width = 200.0f;
    const float track_rounding = 4.0f;

    const float avail_width = ImGui::GetContentRegionAvail().x;
    const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_y_center = cursor_pos.y + slider_height * 0.5f;
    const float track_x1 = cursor_pos.x;
    const float track_y1 = track_y_center - slider_height * 0.5f;
    const float track_x2 = track_x1 + draw_width;
    const float track_y2 = track_y_center + slider_height * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // Draw track
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // Map value to position
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
    const float grab_center_y = track_y_center;

    // Draw circle handle
    const ImVec4 grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 1.0f)
            : ImVec4(0.0f, 0.8f, 1.0f, 1.0f);
    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(grab_color));

    // Interaction logic
    const ImRect interact_rect(track_x1, track_y1 - grab_radius,
                               track_x2, track_y2 + grab_radius);
    bool value_changed = false;

    ImGui::ItemSize(ImVec2(draw_width, slider_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");
 
        if (ImGui::ItemAdd(interact_rect, id)) {
            if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
                ImGui::ClearActiveID();
            }

            if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
                if (interact_rect.Contains(g->IO.MousePos)) {
                    ImGui::SetActiveID(id, g->CurrentWindow);
                    float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                             (track_x2 - track_x1 - 2 * grab_radius));
                    *v = v_min + (v_max - v_min) * new_t;
                    value_changed = true;
                }
            }
            else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
                float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                         (track_x2 - track_x1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
    

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}

bool MacStyleSliderFloatV2(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    // ----------------------------
    // 核心参数设置
    // ----------------------------
    const float slider_height = 16.0f;          // 轨道高度
    const float grab_radius = slider_height;    // 滑块半径 = 轨道高度
    const float total_width = 200.0f;
    const float track_rounding = 4.0f;

    const float avail_width = ImGui::GetContentRegionAvail().x;
    const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_y_center = cursor_pos.y + slider_height * 0.5f;

    const float track_x1 = cursor_pos.x;
    const float track_x2 = track_x1 + draw_width;
    const float track_y1 = track_y_center - slider_height * 0.5f;
    const float track_y2 = track_y_center + slider_height * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // 绘制轨道
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // 映射值到位置
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
    const float grab_center_y = track_y_center;

    // 绘制圆形滑块
    const ImVec4 grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 1.0f)
            : ImVec4(0.0f, 0.8f, 1.0f, 1.0f);
    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(grab_color));

    // ----------------------------
    // 更新可交互区域：高度 = 滑块直径（2 * grab_radius）
    // ----------------------------
    const ImRect interact_rect(
        track_x1, grab_center_y - grab_radius,   // 上边界 = 中心 - 半径
        track_x2, grab_center_y + grab_radius);  // 下边界 = 中心 + 半径

    bool value_changed = false;

    ImGui::ItemSize(ImVec2(draw_width, slider_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");

    if (ImGui::ItemAdd(interact_rect, id)) {
        if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
            ImGui::ClearActiveID();
        }

        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
            if (interact_rect.Contains(g->IO.MousePos)) {
                ImGui::SetActiveID(id, g->CurrentWindow);
                float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                         (track_x2 - track_x1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
        else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
            float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                     (track_x2 - track_x1 - 2 * grab_radius));
            *v = v_min + (v_max - v_min) * new_t;
            value_changed = true;
        }
    }

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}


bool MacStyleSliderFloatV3(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    // ----------------------------
    // 核心参数修改：轨道高度减半
    // ----------------------------
    const float slider_height = 8.0f;           // ← 高度减半
    const float grab_radius = slider_height;    // 滑块半径 = 轨道高度
    const float total_width = 200.0f;
    const float track_rounding = 2.0f;          // 圆角也减半，保持比例协调

    const float avail_width = ImGui::GetContentRegionAvail().x;
    const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_y_center = cursor_pos.y + slider_height * 0.5f;

    const float track_x1 = cursor_pos.x;
    const float track_x2 = track_x1 + draw_width;
    const float track_y1 = track_y_center - slider_height * 0.5f;
    const float track_y2 = track_y_center + slider_height * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // 绘制轨道
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // 映射值到位置
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
    const float grab_center_y = track_y_center;

    // ----------------------------
    // 滑块颜色改为半透明
    // ----------------------------
    const ImVec4 grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)   // 半透明蓝色
            : ImVec4(0.0f, 0.8f, 1.0f, 0.5f); // 半透明浅蓝
    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(grab_color));

    // 可交互区域（宽度 = 轨道宽度，高度 = 滑块直径）
    const ImRect interact_rect(
        track_x1, grab_center_y - grab_radius,
        track_x2, grab_center_y + grab_radius);

    bool value_changed = false;

    ImGui::ItemSize(ImVec2(draw_width, slider_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");

    if (ImGui::ItemAdd(interact_rect, id)) {
        if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
            ImGui::ClearActiveID();
        }

        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
            if (interact_rect.Contains(g->IO.MousePos)) {
                ImGui::SetActiveID(id, g->CurrentWindow);
                float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                         (track_x2 - track_x1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
        else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
            float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                     (track_x2 - track_x1 - 2 * grab_radius));
            *v = v_min + (v_max - v_min) * new_t;
            value_changed = true;
        }
    }

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}


bool MacStyleSliderFloatV4(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    // ----------------------------
    // 核心参数设置
    // ----------------------------
    const float slider_height = 8.0f;           // ← 当前轨道高度
    const float grab_radius = slider_height * 1.5f; // ← 滑块半径 = 1.5×轨道高度 → 直径=3×轨道高度
    const float total_width = 200.0f;
    const float track_rounding = 2.0f;

    const float avail_width = ImGui::GetContentRegionAvail().x;
    const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_y_center = cursor_pos.y + slider_height * 0.5f;

    const float track_x1 = cursor_pos.x;
    const float track_x2 = track_x1 + draw_width;
    const float track_y1 = track_y_center - slider_height * 0.5f;
    const float track_y2 = track_y_center + slider_height * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // 绘制轨道
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // 映射值到位置
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
    const float grab_center_y = track_y_center;

    // 滑块颜色改为半透明
    const ImVec4 grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)
            : ImVec4(0.0f, 0.8f, 1.0f, 0.5f);
    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(grab_color));

    // ----------------------------
    // 更新可交互区域：高度 = 滑块直径（3×轨道高度）
    // ----------------------------
    const ImRect interact_rect(
        track_x1, grab_center_y - grab_radius,   // 上边界 = 中心 - 半径
        track_x2, grab_center_y + grab_radius);  // 下边界 = 中心 + 半径

    bool value_changed = false;

    ImGui::ItemSize(ImVec2(draw_width, slider_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");

    if (ImGui::ItemAdd(interact_rect, id)) {
        if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
            ImGui::ClearActiveID();
        }

        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
            if (interact_rect.Contains(g->IO.MousePos)) {
                ImGui::SetActiveID(id, g->CurrentWindow);
                float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                         (track_x2 - track_x1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
        else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
            float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                     (track_x2 - track_x1 - 2 * grab_radius));
            *v = v_min + (v_max - v_min) * new_t;
            value_changed = true;
        }
    }

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}


// bool MacStyleSliderFloatV5(const char* label, float* v, float v_min, float v_max) {
//     ImGuiContext* g = ImGui::GetCurrentContext();
//     const ImGuiStyle& style = g->Style;

//     ImGui::PushID(label);
//     ImGui::BeginGroup();

//     const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
//     ImGui::AlignTextToFramePadding();
//     ImGui::TextUnformatted(label);
//     ImGui::SameLine();

//     // ----------------------------
//     // 核心参数设置
//     // ----------------------------
//     const float slider_height = 8.0f;           // 当前轨道高度
//     const float grab_radius = slider_height * 1.5f; // 滑块半径 = 1.5×轨道高度 → 直径=3×轨道高度
//     const float total_width = 200.0f;
//     const float track_rounding = 2.0f;

//     const float avail_width = ImGui::GetContentRegionAvail().x;
//     const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

//     const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
//     const float track_y_center = cursor_pos.y + slider_height * 0.5f;

//     const float track_x1 = cursor_pos.x;
//     const float track_x2 = track_x1 + draw_width;
//     const float track_y1 = track_y_center - slider_height * 0.5f;
//     const float track_y2 = track_y_center + slider_height * 0.5f;

//     ImDrawList* draw_list = ImGui::GetWindowDrawList();

//     // 绘制轨道
//     const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
//     draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
//                              ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

//     // 映射值到位置
//     const float t = (*v - v_min) / (v_max - v_min);
//     float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
//     const float grab_center_y = track_y_center;

//     // 获取基础颜色
//     const ImVec4 base_grab_color =
//         ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
//             ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)
//             : ImVec4(0.0f, 0.8f, 1.0f, 0.5f);

//     // ----------------------------
//     // 提高亮度至 1.5 倍
//     // ----------------------------
//     float r = base_grab_color.x, g_ = base_grab_color.y, b = base_grab_color.z, a = base_grab_color.w;
//     float h, s, v;
//     ImGui::ColorConvertRGBtoHSV(r, g_, b, h, s, v);
//     v = ImClamp(v * 1.5f, 0.0f, 1.0f); // 提高亮度至 1.5 倍
//     ImVec3 brightened = ImGui::ColorConvertHSVtoRGB(h, s, v);
//     ImVec4 highlight_color(brightened.x, brightened.y, brightened.z, a); // 保留透明度

//     // ----------------------------
//     // 绘制两个同心圆：先画大圆（原 handle），再画小圆（新增的高亮层）
//     // ----------------------------
//     draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
//                                ImGui::ColorConvertFloat4ToU32(base_grab_color));

//     draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), slider_height,
//                                ImGui::ColorConvertFloat4ToU32(highlight_color));

//     // ----------------------------
//     // 更新可交互区域：高度 = 滑块直径（3×轨道高度）
//     // ----------------------------
//     const ImRect interact_rect(
//         track_x1, grab_center_y - grab_radius,   // 上边界 = 中心 - 半径
//         track_x2, grab_center_y + grab_radius);  // 下边界 = 中心 + 半径

//     bool value_changed = false;

//     ImGui::ItemSize(ImVec2(draw_width, slider_height));
//     const ImGuiID id = g->CurrentWindow->GetID("slider");

//     if (ImGui::ItemAdd(interact_rect, id)) {
//         if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
//             ImGui::ClearActiveID();
//         }

//         if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
//             if (interact_rect.Contains(g->IO.MousePos)) {
//                 ImGui::SetActiveID(id, g->CurrentWindow);
//                 float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
//                                          (track_x2 - track_x1 - 2 * grab_radius));
//                 *v = v_min + (v_max - v_min) * new_t;
//                 value_changed = true;
//             }
//         }
//         else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
//             float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
//                                      (track_x2 - track_x1 - 2 * grab_radius));
//             *v = v_min + (v_max - v_min) * new_t;
//             value_changed = true;
//         }
//     }

//     ImGui::EndGroup();
//     ImGui::PopID();

//     return value_changed;
// }



#include "imgui.h"
#include "imgui_internal.h"

bool MacStyleSliderFloatV5(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    // ----------------------------
    // 核心参数设置
    // ----------------------------
    const float slider_height = 8.0f;           // ← 当前轨道高度
    const float grab_radius = slider_height * 1.5f; // ← 滑块半径 = 1.5×轨道高度 → 直径=3×轨道高度
    const float total_width = 200.0f;
    const float track_rounding = 2.0f;

    const float avail_width = ImGui::GetContentRegionAvail().x;
    const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_y_center = cursor_pos.y + slider_height * 0.5f;

    const float track_x1 = cursor_pos.x;
    const float track_x2 = track_x1 + draw_width;
    const float track_y1 = track_y_center - slider_height * 0.5f;
    const float track_y2 = track_y_center + slider_height * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // 绘制轨道
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // 映射值到位置
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
    const float grab_center_y = track_y_center;

    // 获取基础颜色
    const ImVec4 base_grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)
            : ImVec4(0.0f, 0.8f, 1.0f, 0.5f);

    // 提取 RGB 分量
    float r = base_grab_color.x, g_ = base_grab_color.y, b = base_grab_color.z, a = base_grab_color.w;

    // 转换为 HSV 并调整亮度
    float h, s, vv;
    ImGui::ColorConvertRGBtoHSV(r, g_, b, h, s, vv);
    vv = ImClamp(vv * 1.5f, 0.0f, 1.0f); // 提高亮度至 1.5 倍

    // 转回 RGB
    float r2, g2, b2;
    ImGui::ColorConvertHSVtoRGB(h, s, vv, r2, g2, b2);
    const ImVec4 highlight_color(r2, g2, b2, a); // 保持透明度不变

    // ----------------------------
    // 绘制两个同心圆：先画大圆（原 handle），再画小圆（新增的高亮层）
    // ----------------------------
    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(base_grab_color));

    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), slider_height,
                               ImGui::ColorConvertFloat4ToU32(highlight_color));

    // ----------------------------
    // 更新可交互区域：高度 = 滑块直径（3×轨道高度）
    // ----------------------------
    const ImRect interact_rect(
        track_x1, grab_center_y - grab_radius,   // 上边界 = 中心 - 半径
        track_x2, grab_center_y + grab_radius);  // 下边界 = 中心 + 半径

    bool value_changed = false;

    ImGui::ItemSize(ImVec2(draw_width, slider_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");

    if (ImGui::ItemAdd(interact_rect, id)) {
        if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
            ImGui::ClearActiveID();
        }

        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
            if (interact_rect.Contains(g->IO.MousePos)) {
                ImGui::SetActiveID(id, g->CurrentWindow);
                float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                         (track_x2 - track_x1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
        else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
            float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                     (track_x2 - track_x1 - 2 * grab_radius));
            *v = v_min + (v_max - v_min) * new_t;
            value_changed = true;
        }
    }

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}



#include "imgui.h"
#include "imgui_internal.h"

#include "imgui.h"
#include "imgui_internal.h"

bool MacStyleSliderFloatV6(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    // ----------------------------
    // 核心参数设置
    // ----------------------------
    const float slider_height = 8.0f;           // 轨道高度
    const float grab_radius = slider_height * 1.5f; // 滑块半径 = 1.5×轨道高度 → 直径=3×轨道高度
    const float total_width = 200.0f;
    const float track_rounding = 2.0f;

    const float avail_width = ImGui::GetContentRegionAvail().x;
    const float draw_width = (avail_width > 0.0f) ? avail_width : total_width;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_y_center = cursor_pos.y + slider_height * 0.5f;

    const float track_x1 = cursor_pos.x;
    const float track_x2 = track_x1 + draw_width;
    const float track_y1 = track_y_center - slider_height * 0.5f;
    const float track_y2 = track_y_center + slider_height * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // 绘制轨道
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // 映射值到位置
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_x = ImLerp(track_x1 + grab_radius, track_x2 - grab_radius, t);
    const float grab_center_y = track_y_center;

    // 获取基础颜色
    const ImVec4 base_grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)
            : ImVec4(0.0f, 0.8f, 1.0f, 0.5f);

    // 提取 RGB 分量
    float r = base_grab_color.x, g_ = base_grab_color.y, b = base_grab_color.z, a = base_grab_color.w;

    // 转换为 HSV 并调整亮度
    float h, s, vv;
    ImGui::ColorConvertRGBtoHSV(r, g_, b, h, s, vv);
    vv = ImClamp(vv * 1.5f, 0.0f, 1.0f); // 提高亮度至 1.5 倍

    // 转回 RGB
    float r2, g2, b2;
    ImGui::ColorConvertHSVtoRGB(h, s, vv, r2, g2, b2);
    const ImVec4 highlight_color(r2, g2, b2, a); // 保持透明度不变

    // ----------------------------
    // 绘制两个同心圆：先画大圆（原 handle），再画小圆（新增的高亮层）
    // ----------------------------

    // 在旧版 ImGui 中，AddCircleFilled 和 AddCircle 不支持 anti_aliased 参数
    // 我们使用默认抗锯齿行为即可（默认是开启的）

    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(base_grab_color));

    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), slider_height,
                               ImGui::ColorConvertFloat4ToU32(highlight_color));

    // ----------------------------
    // 【可选】添加内圈描边（增强视觉识别）
    // ----------------------------
    const float outline_width = 1.0f;
    const ImVec4 outline_color = ImVec4(0.0f, 0.0f, 0.0f, 0.5f); // 黑色半透明描边

    draw_list->AddCircle(ImVec2(grab_center_x, grab_center_y),
                         slider_height + outline_width,
                         ImGui::ColorConvertFloat4ToU32(outline_color),
                         0, // num_segments 自动计算
                         outline_width);

    // ----------------------------
    // 更新可交互区域：高度 = 滑块直径（3×轨道高度）
    // ----------------------------
    const ImRect interact_rect(
        track_x1, grab_center_y - grab_radius,   // 上边界 = 中心 - 半径
        track_x2, grab_center_y + grab_radius);  // 下边界 = 中心 + 半径

    bool value_changed = false;

    ImGui::ItemSize(ImVec2(draw_width, slider_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");

    if (ImGui::ItemAdd(interact_rect, id)) {
        if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
            ImGui::ClearActiveID();
        }

        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
            if (interact_rect.Contains(g->IO.MousePos)) {
                ImGui::SetActiveID(id, g->CurrentWindow);
                float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                         (track_x2 - track_x1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
        else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
            float new_t = ImSaturate((g->IO.MousePos.x - (track_x1 + grab_radius)) /
                                     (track_x2 - track_x1 - 2 * grab_radius));
            *v = v_min + (v_max - v_min) * new_t;
            value_changed = true;
        }
    }

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}




#include "imgui.h"
#include "imgui_internal.h"

bool MacStyleSliderFloatVertical(const char* label, float* v, float v_min, float v_max) {
    ImGuiContext* g = ImGui::GetCurrentContext();
    const ImGuiStyle& style = g->Style;

    ImGui::PushID(label);
    ImGui::BeginGroup();

    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
    ImGui::AlignTextToFramePadding();
    ImGui::TextUnformatted(label);
    ImGui::SameLine();

    // ----------------------------
    // 核心参数设置
    // ----------------------------
    const float slider_width = 8.0f;           // ← 垂直轨道宽度（相当于水平版的轨道高度）
    const float grab_radius = slider_width * 1.5f; // 滑块半径 = 1.5×轨道宽度 → 直径=3×轨道宽度
    const float total_height = 200.0f;
    const float track_rounding = 2.0f;

    const float avail_height = ImGui::GetContentRegionAvail().y;
    const float draw_height = (avail_height > 0.0f) ? avail_height : total_height;

    const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();
    const float track_x_center = cursor_pos.x + slider_width * 0.5f;

    const float track_y1 = cursor_pos.y;
    const float track_y2 = track_y1 + draw_height;
    const float track_x1 = track_x_center - slider_width * 0.5f;
    const float track_x2 = track_x_center + slider_width * 0.5f;

    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // 绘制轨道
    const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
    draw_list->AddRectFilled(cursor_pos, ImVec2(track_x2, track_y2),
                             ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

    // 映射值到位置（从下到上）
    const float t = (*v - v_min) / (v_max - v_min);
    float grab_center_y = ImLerp(track_y2 - grab_radius, track_y1 + grab_radius, t); // 注意：从下往上递增
    const float grab_center_x = track_x_center;

    // 获取基础颜色
    const ImVec4 base_grab_color =
        ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
            ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)
            : ImVec4(0.0f, 0.8f, 1.0f, 0.5f);

    // 提取 RGB 分量并调整亮度
    float r = base_grab_color.x, g_ = base_grab_color.y, b = base_grab_color.z, a = base_grab_color.w;
    float h, s, vv;
    ImGui::ColorConvertRGBtoHSV(r, g_, b, h, s, vv);
    vv = ImClamp(vv * 1.5f, 0.0f, 1.0f); // 提高亮度至 1.5 倍
    float r2, g2, b2;
    ImGui::ColorConvertHSVtoRGB(h, s, vv, r2, g2, b2);
    const ImVec4 highlight_color(r2, g2, b2, a); // 保持透明度不变

    // ----------------------------
    // 绘制两个同心圆：先画大圆（原 handle），再画小圆（新增的高亮层）
    // ----------------------------

    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), grab_radius,
                               ImGui::ColorConvertFloat4ToU32(base_grab_color));

    draw_list->AddCircleFilled(ImVec2(grab_center_x, grab_center_y), slider_width,
                               ImGui::ColorConvertFloat4ToU32(highlight_color));

    // ----------------------------
    // 【可选】添加内圈描边（增强视觉识别）
    // ----------------------------
    const float outline_width = 1.0f;
    const ImVec4 outline_color = ImVec4(0.0f, 0.0f, 0.0f, 0.5f); // 黑色半透明描边

    draw_list->AddCircle(ImVec2(grab_center_x, grab_center_y),
                         slider_width + outline_width,
                         ImGui::ColorConvertFloat4ToU32(outline_color),
                         0, // num_segments 自动计算
                         outline_width);

    // ----------------------------
    // 更新可交互区域：宽度 = 滑块直径（3×轨道宽度）
    // ----------------------------
    const ImRect interact_rect(
        grab_center_x - grab_radius, track_y1,   // 左边界 = 中心 - 半径
        grab_center_x + grab_radius, track_y2);  // 右边界 = 中心 + 半径

    bool value_changed = false;

    ImGui::ItemSize(ImVec2(slider_width, draw_height));
    const ImGuiID id = g->CurrentWindow->GetID("slider");

    if (ImGui::ItemAdd(interact_rect, id)) {
        if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
            ImGui::ClearActiveID();
        }

        if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
            if (interact_rect.Contains(g->IO.MousePos)) {
                ImGui::SetActiveID(id, g->CurrentWindow);
                float new_t = ImSaturate((track_y2 - g->IO.MousePos.y) /
                                         (track_y2 - track_y1 - 2 * grab_radius));
                *v = v_min + (v_max - v_min) * new_t;
                value_changed = true;
            }
        }
        else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
            float new_t = ImSaturate((track_y2 - g->IO.MousePos.y) /
                                     (track_y2 - track_y1 - 2 * grab_radius));
            *v = v_min + (v_max - v_min) * new_t;
            value_changed = true;
        }
    }

    ImGui::EndGroup();
    ImGui::PopID();

    return value_changed;
}


// #include "imgui.h"
// #include "imgui_internal.h"

// enum SliderOrientation {
//     HORIZONTAL,
//     VERTICAL
// };

// bool MacStyleSliderFloatCommon(const char* label, float* v, float v_min, float v_max, SliderOrientation orientation) {
//     ImGuiContext* g = ImGui::GetCurrentContext();
//     const ImGuiStyle& style = g->Style;

//     ImGui::PushID(label);
//     ImGui::BeginGroup();

//     const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
//     ImGui::AlignTextToFramePadding();
//     ImGui::TextUnformatted(label);
//     ImGui::SameLine();

//     // ----------------------------
//     // 核心参数设置
//     // ----------------------------
//     const float slider_dim = 8.0f;           // 轨道宽度/高度（取决于方向）
//     const float grab_radius = slider_dim * 1.5f; // 滑块半径 = 1.5×轨道尺寸 → 直径=3×轨道尺寸
//     const float total_dim = 200.0f;
//     const float track_rounding = 2.0f;

//     const ImVec2 cursor_pos = ImGui::GetCursorScreenPos();

//     ImDrawList* draw_list = ImGui::GetWindowDrawList();

//     float draw_length;
//     ImVec2 track_start, track_end;
//     if (orientation == HORIZONTAL) {
//         const float avail_width = ImGui::GetContentRegionAvail().x;
//         draw_length = (avail_width > 0.0f) ? avail_width : total_dim;

//         track_start = ImVec2(cursor_pos.x, cursor_pos.y + slider_dim * 0.5f);
//         track_end = ImVec2(track_start.x + draw_length, track_start.y);

//         // 映射值到位置
//         const float t = (*v - v_min) / (v_max - v_min);
//         float grab_center_x = ImLerp(track_start.x + grab_radius, track_end.x - grab_radius, t);
//         const float grab_center_y = track_start.y;

//         // 绘制轨道
//         const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
//         draw_list->AddRectFilled(track_start - ImVec2(0, slider_dim * 0.5f),
//                                  ImVec2(track_end.x, track_end.y + slider_dim * 0.5f),
//                                  ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

//         return HandleInteraction(draw_list, &grab_center_x, grab_center_y, grab_radius, slider_dim, 
//                                  track_start.x, track_end.x, cursor_pos, draw_length, slider_dim, v, v_min, v_max, orientation);
//     } else { // VERTICAL
//         const float avail_height = ImGui::GetContentRegionAvail().y;
//         draw_length = (avail_height > 0.0f) ? avail_height : total_dim;

//         track_start = ImVec2(cursor_pos.x + slider_dim * 0.5f, cursor_pos.y);
//         track_end = ImVec2(track_start.x, track_start.y + draw_length);

//         // 映射值到位置（从下到上）
//         const float t = (*v - v_min) / (v_max - v_min);
//         float grab_center_y = ImLerp(track_end.y - grab_radius, track_start.y + grab_radius, t); // 注意：从下往上递增
//         const float grab_center_x = track_start.x;

//         // 绘制轨道
//         const ImVec4 track_color = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
//         draw_list->AddRectFilled(track_start - ImVec2(slider_dim * 0.5f, 0),
//                                  ImVec2(track_end.x + slider_dim * 0.5f, track_end.y),
//                                  ImGui::ColorConvertFloat4ToU32(track_color), track_rounding);

//         return HandleInteraction(draw_list, &grab_center_x, grab_center_y, grab_radius, slider_dim, 
//                                  track_start.y, track_end.y, cursor_pos, draw_length, slider_dim, v, v_min, v_max, orientation);
//     }

//     ImGui::EndGroup();
//     ImGui::PopID();
// }

// // 辅助函数：处理滑块绘制和交互
// bool HandleInteraction(ImDrawList* draw_list, float* grab_center_x, float grab_center_y, float grab_radius, 
//                        float slider_dim, float track_start, float track_end, ImVec2 cursor_pos, 
//                        float draw_length, float slider_width, float* v, float v_min, float v_max, SliderOrientation orientation) {
//     ImGuiContext* g = ImGui::GetCurrentContext();

//     // 获取基础颜色
//     const ImVec4 base_grab_color =
//         ImGui::IsItemHovered() || g->ActiveId == g->CurrentWindow->GetID("slider")
//             ? ImVec4(0.0f, 0.6f, 1.0f, 0.5f)
//             : ImVec4(0.0f, 0.8f, 1.0f, 0.5f);

//     // 提取 RGB 分量并调整亮度
//     float r = base_grab_color.x, g_ = base_grab_color.y, b = base_grab_color.z, a = base_grab_color.w;
//     float h, s, vv;
//     ImGui::ColorConvertRGBtoHSV(r, g_, b, h, s, vv);
//     vv = ImClamp(vv * 1.5f, 0.0f, 1.0f); // 提高亮度至 1.5 倍
//     float r2, g2, b2;
//     ImGui::ColorConvertHSVtoRGB(h, s, vv, r2, g2, b2);
//     const ImVec4 highlight_color(r2, g2, b2, a); // 保持透明度不变

//     // 绘制两个同心圆：先画大圆（原 handle），再画小圆（新增的高亮层）
//     draw_list->AddCircleFilled(ImVec2(*grab_center_x, grab_center_y), grab_radius,
//                                ImGui::ColorConvertFloat4ToU32(base_grab_color));

//     draw_list->AddCircleFilled(ImVec2(*grab_center_x, grab_center_y), slider_dim,
//                                ImGui::ColorConvertFloat4ToU32(highlight_color));

//     // 添加内圈描边（增强视觉识别）
//     const float outline_width = 1.0f;
//     const ImVec4 outline_color = ImVec4(0.0f, 0.0f, 0.0f, 0.5f); // 黑色半透明描边
//     draw_list->AddCircle(ImVec2(*grab_center_x, grab_center_y),
//                          slider_dim + outline_width,
//                          ImGui::ColorConvertFloat4ToU32(outline_color),
//                          0, // num_segments 自动计算
//                          outline_width);

//     // 更新可交互区域
//     bool value_changed = false;
//     const ImGuiID id = g->CurrentWindow->GetID("slider");

//     if (orientation == HORIZONTAL) {
//         const ImRect interact_rect(
//             track_start, grab_center_y - grab_radius,   // 上边界 = 中心 - 半径
//             track_end.x, grab_center_y + grab_radius);  // 下边界 = 中心 + 半径

//         ImGui::ItemSize(ImVec2(draw_length, slider_dim));
//         if (ImGui::ItemAdd(interact_rect, id)) {
//             if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
//                 ImGui::ClearActiveID();
//             }

//             if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
//                 if (interact_rect.Contains(g->IO.MousePos)) {
//                     ImGui::SetActiveID(id, g->CurrentWindow);
//                     float new_t = ImSaturate((g->IO.MousePos.x - (track_start + grab_radius)) /
//                                              (track_end.x - track_start - 2 * grab_radius));
//                     *v = v_min + (v_max - v_min) * new_t;
//                     value_changed = true;
//                 }
//             }
//             else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
//                 float new_t = ImSaturate((g->IO.MousePos.x - (track_start + grab_radius)) /
//                                          (track_end.x - track_start - 2 * grab_radius));
//                 *v = v_min + (v_max - v_min) * new_t;
//                 value_changed = true;
//             }
//         }
//     } else { // VERTICAL
//         const ImRect interact_rect(
//             grab_center_x - grab_radius, track_start.y,   // 左边界 = 中心 - 半径
//             grab_center_x + grab_radius, track_end.y);    // 右边界 = 中心 + 半径

//         ImGui::ItemSize(ImVec2(slider_dim, draw_length));
//         if (ImGui::ItemAdd(interact_rect, id)) {
//             if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
//                 ImGui::ClearActiveID();
//             }

//             if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
//                 if (interact_rect.Contains(g->IO.MousePos)) {
//                     ImGui::SetActiveID(id, g->CurrentWindow);
//                     float new_t = ImSaturate((track_end.y - g->IO.MousePos.y) /
//                                              (track_end.y - track_start.y - 2 * grab_radius));
//                     *v = v_min + (v_max - v_min) * new_t;
//                     value_changed = true;
//                 }
//             }
//             else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left) && g->ActiveId == id) {
//                 float new_t = ImSaturate((track_end.y - g->IO.MousePos.y) /
//                                          (track_end.y - track_start.y - 2 * grab_radius));
//                 *v = v_min + (v_max - v_min) * new_t;
//                 value_changed = true;
//             }
//         }
//     }

//     return value_changed;
// }

int main() {
    // Setup error callback
    glfwSetErrorCallback(glfw_error_callback);

    // Initialize GLFW
    if (!glfwInit()) {
        std::cerr << "Failed to initialize GLFW" << std::endl;
        return -1;
    }

    // Setup OpenGL version
#if defined(__APPLE__)
    // GL 3.2 + GLSL 150 (MacOS)
    const char* glsl_version = "#version 150";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);           // Required on MacOS
#else
    // GL 3.0 + GLSL 130 (Windows and Linux)
    const char* glsl_version = "#version 130";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#endif

    // Create window
    GLFWwindow* window = glfwCreateWindow(800, 600, "Example", nullptr, nullptr);
    if (!window) {
        std::cerr << "Failed to create GLFW window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0); // Disable vsync

    // Setup context
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImPlot::CreateContext();
    ImPlot3D::CreateContext();

    // Setup style
    ImGui::StyleColorsDark();

    // Setup backend
    ImGui_ImplGlfw_InitForOpenGL(window, true);
    ImGui_ImplOpenGL3_Init(glsl_version);

    // Main loop
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();

        // Start frame
        ImGui_ImplOpenGL3_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();
static float volume = 0.5f;
if (MacStyleSliderFloatVertical("Volume", &volume, 0.0f, 1.0f)) {
    printf("Volume changed to: %.2f\n", volume);
}
        // Demo windows
        // ImGui::ShowDemoWindow();
        ImPlot::ShowDemoWindow();
        ImPlot3D::ShowDemoWindow();

        // Render
        ImGui::Render();
        int display_w, display_h;
        glfwGetFramebufferSize(window, &display_w, &display_h);
        glViewport(0, 0, display_w, display_h);
        glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

        // Swap buffers
        glfwSwapBuffers(window);
    }

    // Cleanup
    ImGui_ImplOpenGL3_Shutdown();
    ImGui_ImplGlfw_Shutdown();
    ImPlot3D::DestroyContext();
    ImPlot::DestroyContext();
    ImGui::DestroyContext();
    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;
}
